package com.service;


import com.mapper.UserMapper;
import com.pojo.Users;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserService {
    @Resource
    private UserMapper dao;
    /*
     * 通过id获取数据
     */
    public Users login(String Username,String Password) throws Exception{
        List<Users> user=dao.selectByUsernameAndPassword(Username,Password);
        try{
             if(user.size()==0){
                return null;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return user.get(0);
    }
    public boolean signup(Users user){
        try {
            dao.insert(user.getId(),user.getUsername(),user.getPassword(),user.getSex(),user.getSignuptime(),user.getEmail(),user.getPhonenumber());
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    public int selectMaxId(){
        if(dao.selectMaxId()==null)
            return 0;
        else
            return dao.selectMaxId();
    }
}
